package classes.io;

import org.junit.Test;

import java.io.*;

/**
 * 缓冲流
 */
public class BufferedInputOutputReader {
    @Test
    public void test2() {
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("./src/classes/io/a.txt"));   // 缓冲流（处理流）读入，包一层节点流
            bufferedWriter = new BufferedWriter(new FileWriter("./src/classes/io/c.txt"));   //
            String str = null;
            while ((str = bufferedReader.readLine()) != null) {
                bufferedWriter.write(str);
                bufferedWriter.newLine();
                bufferedWriter.flush(); // 刷新缓存
            }


        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (bufferedWriter != null) {
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
